package com.apes.pi.model;

import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 接收者
 *
 * @author wuq
 * @create 2019-10-19 10:10
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = Receiver.CONST_TABLE_NAME)
public class Receiver extends Model {
    public static final String CONST_TABLE_NAME = "pi_Receiver";

    @Id
    @Column(name = "id", nullable = false, length = 32)
    @Comment("接收者编码")
    private String id;

    @Column(name = "name", nullable = false, length = 200)
    @Comment("接收者描述")
    private String name;

    @ManyToOne
    @JoinColumn(name = "connector_id", referencedColumnName = "id")
    private PiConnector connector;

    @OneToMany(mappedBy = "receiver", cascade=CascadeType.ALL, orphanRemoval = true)
    private List<ReceiverParams> params;

    /*public List<ReceiverParams> getParams() {
        if (params == null || params.isEmpty()) return new ArrayList<>();
        for (ReceiverParams item : params) {
            item.setReceiver(this);
        }
        return params;
    }*/

    @Transient
    private List<Pipe> beforePipes;      // 前置拦截器

    @Transient
    private List<Pipe> afterPipes;      // 后置拦截器

}
